import {
  Entity,
  PrimaryColumn,
  Column,
  UpdateDateColumn,
  JoinColumn,
  OneToOne,
} from 'typeorm';
import { ApiProperty } from '@nestjs/swagger';
import { User } from '../../../users/entities/user.entity';

/**
 * 用户钱包实体
 */
@Entity({ name: 'user_wallets', comment: '用户钱包表' })
export class UserWallet {
  @ApiProperty({ description: '用户ID' })
  @PrimaryColumn({ comment: '用户ID，主键' })
  userId: number;

  @ApiProperty({ description: '余额（单位：分）' })
  @Column({ 
    type: 'int',
    default: 0,
    comment: '用户余额，单位分' 
  })
  balance: number;

  @ApiProperty({ description: '代金券余额（单位：分）' })
  @Column({ 
    type: 'int',
    default: 0,
    comment: '代金券余额，单位分' 
  })
  voucherBalance: number;

  @ApiProperty({ description: '更新时间' })
  @UpdateDateColumn({ comment: '记录更新时间' })
  updatedAt: Date;

  // 关联用户
  @OneToOne(() => User)
  @JoinColumn({ name: 'userId' })
  user: User;
}